<template>
<div class="popAddBox">
    <el-dialog title="新增" :visible.sync="dialogFormVisible" width="800px">
        <!-- <el-divider></el-divider> -->
        <el-form :model="addRuleFrom" :rules="addRules" ref="addRuleFrom" label-width="100px">
            <el-form-item label="机构名称：" prop="departName">
                <el-input v-model="addRuleFrom.departName" placeholder="请输入机构/部门名称" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="上级部门" v-show="isparentTitle?true:false">
                <el-input v-model="isparentTitle" disabled></el-input>
            </el-form-item>
            <el-form-item label="机构类型：">
                <el-radio-group v-model="addRuleFrom.orgCategory">
                    <el-radio label="1">公司</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="电话：">
                <el-input v-model="addRuleFrom.mobile" placeholder="请输入电话"></el-input>
            </el-form-item>
            <el-form-item label="传真：">
                <el-input v-model="addRuleFrom.fax" placeholder="请输入传真"></el-input>
            </el-form-item>
            <el-form-item label="地址：">
                <el-input v-model="addRuleFrom.address" placeholder="请输入地址"></el-input>
            </el-form-item>
            <el-form-item label="排序：">
                <el-input-number v-model="addRuleFrom.departOrder" controls-position="right" :min="0" :max="10"></el-input-number>
            </el-form-item>
            <el-form-item label="备注：">
                <el-input type="textarea" v-model="addRuleFrom.memo" placeholder="请输入备注"></el-input>
            </el-form-item>
        </el-form>
        <el-divider></el-divider>
        <div slot="footer" class="dialog-footer">
            <el-button @click="resetForm('addRuleFrom')">关 闭</el-button>
            <el-button type="primary" @click="submitForm('addRuleFrom')">确 定</el-button>
        </div>
    </el-dialog>
</div>

</template>
<script>
import {
        queryTreeListadd
} from "@/api/depart";
export default{
    name:"departlist",
    data(){
        return{
            dialogFormVisible:false,// 弹窗开关状态
            isparentTitle:"",
            addRuleFrom: {
                departName: "",
                orgCategory: "1",
                mobile: "",
                fax: '',
                address: "",
                departOrder: "0",
                memo: "",
                parentId:null
            },// 表单初始状态数据
            addRules:{
                departName:[
                     { required: true, message: '请输入机构/部门名称!', trigger: 'blur' }
                ]
            },
        }
    },
    methods:{
        // 添加部门 添加下级部门 弹窗的确定键
        queryTreeNodeadd(){
            let _self = this;
            _self.addRuleFrom.mobile = _self.addRuleFrom.mobile.trim();
            _self.addRuleFrom.fax = _self.addRuleFrom.fax.trim();
            _self.addRuleFrom.address = _self.addRuleFrom.address.trim();
            _self.addRuleFrom.memo = _self.addRuleFrom.memo.trim();
            let data = _self.addRuleFrom;
            queryTreeListadd(data).then((res)=>{
                if(res.code == 200){
                    let childMessage = res.message;
                    _self.$emit('departSubmit',childMessage);
                }
                
            })
        },
        open(a,b){
            let _self = this;
            this.dialogFormVisible = true;
            _self.addRuleFrom.departName = "";
            _self.addRuleFrom.orgCategory = "1";
            _self.addRuleFrom.mobile = "";
            _self.addRuleFrom.fax = "";
            _self.addRuleFrom.address = "";
            _self.addRuleFrom.departOrder = "0";
            _self.addRuleFrom.memo = "";
            _self.addRuleFrom.parentId = b;
            _self.isparentTitle = a;
        },
        // 确定校验
        submitForm(formName) {
            let _self = this;
            this.$refs[formName].validate(async(valid) => {
                if (valid) {
                    await _self.queryTreeNodeadd();
                     _self.dialogFormVisible = false;
                } else {
                    return false;
                }
            });
        },
        // 重置数据且关闭弹窗
        resetForm(formName) {
            let _self = this;
            this.$refs[formName].resetFields();
            _self.addRuleFrom.departName = "";
            _self.addRuleFrom.orgCategory = "1";
            _self.addRuleFrom.mobile = "";
            _self.addRuleFrom.fax = "";
            _self.addRuleFrom.address = "";
            _self.addRuleFrom.departOrder = "0";
            _self.addRuleFrom.memo = "";
            _self.dialogFormVisible = false;
        }  
    },
    props:{
        treeDataSelectedid:{
            type:String,
            default:()=>{
                return "";
            }
        }
    },

}
</script>
<style lang="less" scoped>
.popAddBox{  
    .dialogAddStyle{

        .departlist_lastitem{
            text-align: end;
        }
        .el-divider--horizontal{
            margin: 0 0 10px 0 ;
        }
    }
}
</style>
